package com.example.hibernate.program;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		try {
			{
				Vehicle vehicle = new Vehicle();
				vehicle.setName("vehicle");
				session.save(vehicle);
			}
			{
				TwoWheeler twoWheeler = new TwoWheeler();
				twoWheeler.setName("bmx");
				twoWheeler.setSteeringHandle("steering handle");
				session.save(twoWheeler);
			}
			{
				FourWheeler fourWheeler = new FourWheeler();
				fourWheeler.setName("honda");
				fourWheeler.setSteeringWheel("steering wheel");
				session.save(fourWheeler);
			}

			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
		}
		session.close();
		sessionFactory.close();
	}
}
